#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <generated/utsrelease.h>
#include "syms.h"
#include "hook.h"
#include "data_aware.h"
#include "sysctl.h"
#include "kprobe_prehook.h"
#include "hook_tk5.h"

#define DRV_VERSION  "1.0.0"

static int __init main_init(void)
{
	int ret;

#ifdef TK5
	ftrace_init_tk5();
#endif

	ret = ksyms_init();
	if (ret < 0)
		return ret;

	ret = patch_init();
	if (ret < 0)
		goto err_patch;

	ret = kprobe_init();
	if (ret < 0)
		goto err_kprobe;
#ifndef TK5
	ret = kretprobe_init();
	if (ret < 0)
		goto err_kretprobe;
#endif
	ret = sysctl_table_init();
	if (ret < 0)
		goto err_sysctl_table;

	ret = data_init();
	if(ret < 0)
		goto err_data_init;

	return 0;

err_data_init:
	sysctl_table_exit();
err_sysctl_table:
#ifndef TK5
	kretprobe_exit();
#endif
err_kretprobe:
	kprobe_exit();
err_kprobe:
	patch_exit();
err_patch:
	return ret;
}

static void __exit main_exit(void)
{
	unload_disable_module();
	sysctl_table_exit();
#ifndef TK5
	kretprobe_exit();
#else //todo kretprobe, just debug here
	ftrace_unhook_work_fn(&ftrace_work);
#endif
	kprobe_exit();
	patch_exit();
	data_exit();
	pr_info("module exit");

}

module_init(main_init);
module_exit(main_exit);
MODULE_DESCRIPTION("hook for test module for tlinux"  UTS_RELEASE);
MODULE_AUTHOR("aurelianliu@tencent.com");
MODULE_VERSION(DRV_VERSION);
MODULE_LICENSE("GPL");
